package com.lineage.data.item_etcitem.add;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1MonsterInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Object;
import com.lineage.server.serverpackets.S_DoActionGFX;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.World;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;

public class newskillbook4 extends ItemExecutor {
  private int _count = 0;
  
  private int _dmgMin = 0;
  
  private int _dmgMax = 0;
  
  private int _chance = 0;
  
  private int _dmgMin_bon = 0;
  
  private int _dmgMax_bon = 0;
  
  private int _gfxId = 0;
  
  private int _itemId = 0;
  
  private int _itemCount = 0;
  
  private Random _randon = new Random();
  
  public static ItemExecutor get() {
    return new newskillbook4();
  }
  
  public void execute(int[] data, L1PcInstance user, L1ItemInstance item) {
    if (user == null)
      return; 
    if (item == null)
      return; 
    if (!user.getInventory().checkItem(this._itemId, this._itemCount)) {
      user.sendPackets((ServerBasePacket)new S_SystemMessage("施法材料不足"));
      return;
    } 
    user.getInventory().consumeItem(this._itemId, this._itemCount);
    user.sendPacketsAll((ServerBasePacket)new S_SkillSound(user.getId(), this._gfxId));
    int dmg = 0;
    if (this._dmgMax - this._dmgMin <= 0) {
      dmg = this._dmgMin;
    } else {
      dmg = this._randon.nextInt(this._dmgMax - this._dmgMin) + this._dmgMin;
    } 
    if (this._randon.nextInt(100) < this._chance)
      if (this._dmgMax_bon - this._dmgMin_bon <= 0) {
        dmg = this._dmgMin_bon;
      } else {
        dmg = this._randon.nextInt(this._dmgMax_bon - this._dmgMin_bon) + this._dmgMin_bon;
      }  
    if (this._count > 1) {
      ArrayList<L1Object> list = World.get().getVisibleObjects((L1Object)user, this._count);
      if (list != null) {
        Iterator<L1Object> iterator = list.iterator();
        while (iterator.hasNext()) {
          L1Object object = iterator.next();
          if (object instanceof L1MonsterInstance) {
            L1MonsterInstance mob = (L1MonsterInstance)object;
            mob.receiveDamage((L1Character)user, dmg);
            mob.broadcastPacketX10((ServerBasePacket)new S_DoActionGFX(mob.getId(), 2));
          } 
        } 
        user.sendPacketsX10((ServerBasePacket)new S_SkillSound(user.getId(), this._gfxId));
      } 
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this._count = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
    try {
      this._dmgMin = Integer.parseInt(set[2]);
    } catch (Exception exception) {}
    try {
      this._dmgMax = Integer.parseInt(set[3]);
    } catch (Exception exception) {}
    try {
      this._chance = Integer.parseInt(set[4]);
    } catch (Exception exception) {}
    try {
      this._dmgMin_bon = Integer.parseInt(set[5]);
    } catch (Exception exception) {}
    try {
      this._dmgMax_bon = Integer.parseInt(set[6]);
    } catch (Exception exception) {}
    try {
      this._gfxId = Integer.parseInt(set[7]);
    } catch (Exception exception) {}
    try {
      this._itemId = Integer.parseInt(set[8]);
    } catch (Exception exception) {}
    try {
      this._itemCount = Integer.parseInt(set[9]);
    } catch (Exception exception) {}
  }
}
